package com.example.xzc.cainiaoshangcheng.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.xzc.cainiaoshangcheng.ViewHolder.BaseViewHolder;

import java.util.List;

/**
 * @projectName: CaiNiaoShangCheng    ---------> 项目名称
 * @description: --------->描述
 * @author: xzc                              --------->作者
 * @date: 2017-03-13    --------->日期
 * @time: 22:29               --------->时间
 */

public abstract class BaseAdapter<T,H extends BaseViewHolder> extends RecyclerView.Adapter<BaseViewHolder>{

    protected List<T> mDatas;
    protected Context mContext;
    protected int mLayoutId;
    protected LayoutInflater mLayoutInflater;


    public BaseAdapter(List<T> datas, Context context, int layoutId){
        this.mContext = context;
        this.mDatas = datas;
        this.mLayoutId = layoutId;

        mLayoutInflater = LayoutInflater.from(context);

    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mLayoutInflater.inflate(mLayoutId,null);
        return new BaseViewHolder(view);
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {

        bindDatas(holder,mDatas.get(position));

    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public abstract void bindDatas(BaseViewHolder holder,T t);
}
